package com.clz.test;

import java.util.ArrayList;
import java.util.List;

public class T2 {
    public static void main(String[] args) {
        //创建分子和分母的数列
        List<Integer> list=denominator(21);
        //计算每一项的值并求和
        double sum =0;
        String s="";
        for (int i = 0; i <list.size()-1; i++) {
            double num = (double) list.get(i+1) / list.get(i);
            s+=" "+list.get(i+1)+"/"+list.get(i)+"+";
            sum+=num;
        }
        System.out.println(s);
        System.out.println("结果为："+sum);
    }

    public static List<Integer> denominator(int n) {
        List<Integer> list =new ArrayList<>();
        int a=1;
        int b=1;
        int sum=1;
        list.add(1);
        while (sum<n){
            int num=a+b;
            list.add(num);
            a=b;
            b=num;
            sum++;
        }
    return list;
    }

}

